//
//  KHHSearchTableViewCell.m
//  Travel
//
//  Created by dllo on 15/12/2.
//  Copyright © 2015年 doll. All rights reserved.
//

#import "KHHSearchTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface KHHSearchTableViewCell ()
@property (nonatomic, retain)UIImageView *whiteImg;
@property (nonatomic, retain)UIImageView *photo;
@property (nonatomic, retain)UILabel *labelTitle;
@property (nonatomic, retain)UILabel *daycountLabel;
@property (nonatomic, retain)UIImageView *dieLikeImg;
@property (nonatomic, retain)UILabel *likeLabel;
@property (nonatomic, retain)UIImageView *dieMileImg;
@property (nonatomic, retain)UILabel *mileLabel;
@end

@implementation KHHSearchTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}
- (void)createView
{
    self.whiteImg = [[UIImageView alloc]init];
    self.whiteImg.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.whiteImg];
    
    self.photo = [[UIImageView alloc]init];
    [self.whiteImg addSubview:self.photo];
    
    self.labelTitle = [[UILabel alloc]init];
    [self.whiteImg addSubview:self.labelTitle];
    self.labelTitle.textColor = [UIColor colorWithRed:0.29 green:0.74 blue:0.81 alpha:1];
    
    self.daycountLabel = [[UILabel alloc]init];
    self.daycountLabel.font = [UIFont systemFontOfSize:10];
    [self.whiteImg addSubview:self.daycountLabel];
    
    self.dieLikeImg = [[UIImageView alloc]init];
    [self.whiteImg addSubview:self.dieLikeImg];
    self.dieLikeImg.image = [UIImage imageNamed:@"XING"];
    
    self.likeLabel = [[UILabel alloc]init];
    [self.whiteImg addSubview:self.likeLabel];
    self.likeLabel.font = [UIFont systemFontOfSize:10];
    
    self.dieMileImg = [[UIImageView alloc]init];
    self.dieMileImg.image = [UIImage imageNamed:@"KM"];
    [self.whiteImg addSubview:self.dieMileImg];
    
    self.mileLabel = [[UILabel alloc]init];
    [self.whiteImg addSubview:self.mileLabel];
    self.mileLabel.font = [UIFont systemFontOfSize:10];
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
//    //夜间模式
//    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"isNight"]) {
//        self.contentView.backgroundColor = [UIColor colorWithRed:0.28 green:0.28 blue:0.28 alpha:1];
//        self.whiteImg.backgroundColor = [UIColor blackColor];
//        self.daycountLabel.textColor = [UIColor whiteColor];
//        self.likeLabel.textColor = [UIColor whiteColor];
//        self.mileLabel.textColor = [UIColor whiteColor];
//    }else
//    {
//        self.contentView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
//    }
    self.whiteImg.frame = CGRectMake(10, 10, HHWIDTH - 20, HHHEIGHT - 10);
    self.photo.frame = CGRectMake(0, 0, self.whiteImg.frame.size.height, self.whiteImg.frame.size.height);
    
    self.labelTitle.frame = CGRectMake(self.photo.frame.size.width + 10, 10, WIDTH - self.photo.frame.size.width - 40, 20);
    
    self.daycountLabel.frame = CGRectMake(self.labelTitle.frame.origin.x, self.labelTitle.frame.origin.y + self.labelTitle.frame.size.height + 10, self.labelTitle.frame.size.width, 10);
    
    self.dieLikeImg.frame = CGRectMake(self.labelTitle.frame.origin.x, self.daycountLabel.frame.origin.y + self.daycountLabel.frame.size.height + 10, 10 , 10);
    
    self.likeLabel.frame = CGRectMake(self.dieLikeImg.frame.origin.x + 13, self.dieLikeImg.frame.origin.y, self.labelTitle.frame.size.width / 2 - 15,10);
    
    self.dieMileImg.frame = CGRectMake(self.likeLabel.frame.origin.x + self.likeLabel.frame.size.width, self.dieLikeImg.frame.origin.y, 10 , 10);
    self.mileLabel.frame = CGRectMake(self.dieMileImg.frame.origin.x + 13, self.dieMileImg.frame.origin.y, self.likeLabel.frame.size.width, 10);
    
    
}


- (void)setRecommentModel:(KHHRecommendModel *)recommentModel
{
    
    _recommentModel = recommentModel;
    
    [self.photo sd_setImageWithURL:[NSURL URLWithString:recommentModel.cover_image] placeholderImage:nil];
    // self.labelTitle.text = recommentModel.name;
    self.daycountLabel.text = [NSString stringWithFormat:@"%ld %@", recommentModel.day_count.integerValue, @"天"];
    self.likeLabel.text = [NSString stringWithFormat:@"%ld", recommentModel.recommendations.integerValue];
    self.mileLabel.text = [NSString stringWithFormat:@"%ld %@", recommentModel.mileage.integerValue, @"KM"];
    
   // 关键字高亮
    NSMutableAttributedString *newString = [[NSMutableAttributedString alloc] initWithString:recommentModel.name];
    //得到关键字位置
    NSRange range = [recommentModel.name rangeOfString:self.str];
    [newString addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:range];
    //  cell.textLabel.textColor = [UIColor grayColor];
    self.labelTitle.attributedText = newString;
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
